package ee.serge.util;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;

import ee.serge.client.Move;
import ee.serge.client.content.CalculatorContent;
import ee.serge.client.content.FullLoansContent;
import ee.serge.client.content.article.ChoosingALenderContent;
import ee.serge.client.content.article.ContactContent;
import ee.serge.client.content.article.KnowYourRightsContent;
import ee.serge.client.content.cp.LoginContent;
import ee.serge.util.bootstrap.BTabPanel;

public class MainHeader extends BTabPanel {

   private static MainHeader instance;
   
   public static MainHeader get() {
      if (instance == null) instance = new MainHeader();
      return instance;
   }
   
   private Map<Class<? extends Content>, Integer> tabMap;
   
   public MainHeader() {
      super("nav");
      tabMap = new HashMap<Class<? extends Content>, Integer>();
      tabMap.put(CalculatorContent.class, add("Calculator", CalculatorContent.getURLData()));
      tabMap.put(FullLoansContent.class, add("All loans", FullLoansContent.getURLData()));
      tabMap.put(ChoosingALenderContent.class, add("Choosing a lender", ChoosingALenderContent.getURLData()));
      tabMap.put(KnowYourRightsContent.class, add("Know your rights", KnowYourRightsContent.getURLData()));
      tabMap.put(ContactContent.class, add("Contact", ContactContent.getURLData()));
      tabMap.put(LoginContent.class, add("Log in", LoginContent.getURLData()));
      Move.get().addValueChangeHandler(new ValueChangeHandler<Content>() {
         @Override
         public void onValueChange(ValueChangeEvent<Content> event) {
            if (tabMap.containsKey(event.getValue().getClass())) {
               setSelected(tabMap.get(event.getValue().getClass()));
            }
         }
      });
   }
   
}
